/*
  学习目标：重定向组件的使用
*/
import React from 'react';
import { BrowserRouter as Router, NavLink, Route, Switch, Redirect } from 'react-router-dom';
import './index.css';

export default class App extends React.Component {
  render() {
    return (
      <>
        <Router>
          <div>
            <NavLink activeClassName="xxx" exact to="/home">
              首页
            </NavLink>
            <br />
            <NavLink to="/my">我的</NavLink>
            <br />
            <NavLink to="/friend">朋友</NavLink>
            <Switch>
              {/* 💥 Redirect一般要配合exact使用 */}
              <Redirect from="/" to="/home" exact></Redirect>
              <Route path="/home" exact component={Home}></Route>
              <Route path="/my" component={MyMusic}></Route>
              <Route path="/friend" component={Friend}></Route>
              <Route component={NotFound}></Route>
            </Switch>
          </div>
        </Router>
      </>
    );
  }
}

function Friend() {
  return (
    <div>
      <h1>我是Friend父组件</h1>

      <Switch>
        <Route path="/friend/friend2" component={Friend2}></Route>
        <Route path="/friend/friend3" component={Friend3}></Route>
        <Route path="/friend" component={Friend1}></Route>
      </Switch>
    </div>
  );
}

function Friend1() {
  return <h1>朋友1</h1>;
}

function Friend2() {
  return <h1>朋友2</h1>;
}
function Friend3() {
  return <h1>朋友3</h1>;
}

function NotFound(params) {
  return <div>404页面</div>;
}

function Home() {
  return <h1>首页组件</h1>;
}

function MyMusic() {
  return <h1>我的音乐件</h1>;
}
